PTT Kevät 2022 ennustekuvat

Maailman vehnäntuotanto

cereals <- c("Wheat", "Corn", "Soybean")

ptt_data_robo_l("tidy/usda_psd") |> 
  filter(commodity_description %in% cereals,
         attribute_description %in% c( "Production"),
         str_detect(country_name, pattern = "EU", negate =T)) |>
  filter_recode(commodity_description = c(#"Maissi"= "Corn",
                                          "Vehnä" = "Wheat")) |> 
  group_by(attribute_description, market_year, commodity_description) |>
  summarise(value = sum(value, na.rm = T)/1000) |> 
  ungroup() |> 
  mutate( 
    tiedot = "Vehnä", 
    time = lubridate::ymd(paste(market_year+1, "7", "1", sep = "-"))    ) |> 
  filter(time >= start_time) |> 

  ptt_plot(
    title=  "Maailman viljantuotanto",
    grouping = tiedot,
    subtitle = "milj. tonnia",
    caption =  "Lähde: USDA ja PTT",
    rangeslider = FALSE,
    zeroline = F,
    axis_limits = list(y = c(700, 800)),
    hovertext =  list(rounding = 1, unit = "milj. tonnia", extra = "")
  ) |> 
  ptt_plot_add_prediction(pred_data = ennuste_data |> filter(luokka == "Maailman viljantuotanto"),satovuosi = T) |>
  ptt_plot_create_widget()
## i Connecting to robonomistServer at ptt.robonomist.com
## v Connecting to robonomistServer at ptt.robonomist.com [622ms]
## 
## i Connected successfully to robonomistServer 2.5.12
## v Connected successfully to robonomistServer 2.5.12 [87ms]
## 
## \ Requesting get
## | Requesting get
## v Requesting get [4.6s]
## 
## `summarise()` has grouped output by 'attribute_description', 'market_year'. You
## can override using the `.groups` argument.
## No frequency attribute detected for hovertext time format, resorting to default
## %Y/%m/%d.
## Using "maailman_viljantuotanto" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/maailman_viljantuotanto.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>

Viljan tuotanto ja tuottajahinta Suomessa

# Viljan tuotanto Suomessa
ptt_data_robo("StatFin/maa/satot/statfin_satot_pxt_001.px") |>
  filter(viljelykasvi %in% c("Vehnä","Ruis","Ohra", "Kaura")) |>
  mutate(tiedot = viljelykasvi) |>
  filter(time >= start_time) |>
  mutate(time = time + months(6)) |> 
   ptt_plot(
    grouping = tiedot,
    title = "Viljan tuotanto Suomessa",
    subtitle = "tuhatta tonnia",
    caption =  "Lähde: Luke ja PTT",
    rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "tuhatta tonnia", extra = "")
  ) |> 
  ptt_plot_add_prediction(pred_data = ennuste_data |> 
                            filter(luokka == "Viljan tuotanto Suomessa"), satovuosi = T) |>
  ptt_plot_create_widget()
## \ Requesting get
## v Requesting get [254ms]
## 
## Using "viljan_tuotanto_suomessa" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/viljan_tuotanto_suomessa.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
# viljan tuottajahinta
ptt_data_robo_l("luke/02_Maatalous/06_Talous/02_Maataloustuotteiden_tuottajahinnat/07_Tuottajahinnat_Vilja_rypsi_rapsi_kk.px") |>
  filter(hinta == "Perushinta 1)") |>
  filter_recode( laji = c("Vehnä" = "VEHNÄ YHTEENSÄ 2)",
                          "Kaura" = "KAURA YHTEENSÄ 5)",
                          "Ohra" =  "OHRA YHTEENSÄ 3)")) |>
  mutate(tiedot = laji) |> 
  filter(time >= start_time) |>
  group_by(tiedot) |> 
  #mutate(value = 100*(value /lag(value, n = 12, order_by = time)-1)) |> 
  ungroup() |> 
  ptt_plot(
    title=  "Viljan tuottajahinnat Suomessa",
    grouping = tiedot,
    subtitle = "€ / tonni",
    caption =  "Lähde: Luke ja PTT",
    rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "€/tn", extra = "")
  ) |> 
  ptt_plot_add_prediction(pred_data = ennuste_data |> 
                            filter(luokka == "Viljan tuottajahinnat Suomessa"),
                          satovuosi = T) |>
  ptt_plot_create_widget()
## \ Requesting get
## v Requesting get [586ms]
## 
## No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
## Using "viljan_tuottajahinnat_suomessa" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/viljan_tuottajahinnat_suomessa.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>

Maidon tuotanto

# Maidon tuotanto 
# 
# ptt_data_robo("luke/02_Maatalous/04_Tuotanto/02_Maito-_ja_maitotuotetilasto/02_Kuukausitilastot/02_Meijerimaidon_tuotanto_kk.px") |>
#   mutate(year = lubridate::year(time)) |> 
#   filter_recode(
#   tieto = c("Vastaanotettu maitomäärä" = "VASTAANOTETTU MAITOMÄÄRÄ YHTEENSÄ (l) 2)")) |> 
#   group_by(tieto,year) |> 
#   summarise(value = sum(value, na.rm = T), .groups = "drop") |> 
#   ungroup() |> 
#   filter(year >= 2014, year < 2022) |> 
#   mutate(tiedot = tieto,
#          time = as.Date(paste(year, "1", "1", sep = "-"))) |> 
#   ptt_plot(
#   grouping = tiedot, 
#   title ="Maidon tuotanto Suomessa",subtitle = "Litraa",
#     caption  = "Lähde: Luke ja PTT",
#    rangeslider = FALSE,
#     zeroline = F,
#     hovertext =  list(rounding = 1, unit = "litraa", extra = "")
#   ) |> 
#   ptt_plot_add_prediction(pred_data = ennuste_data |> 
#                             filter(luokka == "Maidon tuotanto")) |>
#   ptt_plot_create_widget()

ptt_data_robo_l("luke/02_Maatalous/04_Tuotanto/02_Maito-_ja_maitotuotetilasto/04_Vuositilastot/04_Maidon_kokonaistuotanto.px") |> 
  filter_recode(
  tuotanto_kaytto = c( "Maito yhteensä" = "MAITO YHTEENSÄ")) |> 
  mutate(tiedot = tuotanto_kaytto,
         time = time + months(6)) |> 
  filter(time >= start_time)  |> 
  ptt_plot(
  grouping = tiedot, 
  title ="Maidon tuotanto Suomessa",subtitle = "milj. litraa",
    caption  = "Lähde: Luke ja PTT",
   rangeslider = FALSE,
    zeroline = F, axis_limits = list(y = c(2000,2400)),
    hovertext =  list(rounding = 0, unit = "milj. litraa", extra = "")
  ) |> 
  ptt_plot_add_prediction(pred_data = ennuste_data |> 
                            filter(luokka == "Maidon tuotanto")) |>
  ptt_plot_create_widget()
## \ Requesting get
## v Requesting get [159ms]
## 
## Using "maidon_tuotanto_suomessa" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/maidon_tuotanto_suomessa.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
# Maidon tuottajahinnat suomi ja eu
milk_countries <-
  c(
    Suomi = "FI",
    EU = "EU",
    
    Tanska = "DK",
    Saksa = "DE"
  )

# TODO: Suomi jää muiden viivojen alle mutta factor-levelit kääntämällä Suomi tulee keltaisella viivalla mikä näkyy vähän huonosti. 

ptt_data_robo_l("tidy/dg_agri") |>
  filter(product_desc %in% "Raw Milk",
         country %in% milk_countries) |>
  filter(time >= start_time) |>
  mutate(tiedot = factor(country, milk_countries, names(milk_countries))) |>

  ptt_plot(
  grouping = tiedot, 
  title ="Maidon tuottajahinta",subtitle = "€ / 100kg",
    caption  = "DG Agri ja PTT",
   rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "€ / 100kg", extra = "")
  ) |> 
  ptt_plot_add_prediction(pred_data = ennuste_data |> 
                            filter(luokka == "Maidon tuottajahinta keskimäärin")) |>
  ptt_plot_create_widget()
## \ Requesting get
## v Requesting get [464ms]
## 
## Using "maidon_tuottajahinta" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/maidon_tuottajahinta.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>

Lihantuotanto

# tuottajahinnat 

 ptt_data_robo("StatFin/hin/mthi/statfin_mthi_pxt_11fp.px") |> 
    filter_recode(
      maatalouden_tuottajahintaindeksin_luokitus =
             c("Naudanliha" = "111000 Nauta",
               "Sianliha" = "112000 Siat",
               "Siipikarjanliha" = "115000 Siipikarja"),
           tiedot = "Maatalouden tuottajahintaindeksi (2015=100)") |> 
  group_by(across(where(is.factor))) |> 
    mutate(value = pc(value, 12, order_by = time),
           luokka = "Lihan tuottajahinnat Suomessa",
           tiedot =  maatalouden_tuottajahintaindeksin_luokitus    ) |>
  ungroup() |> 
  filter(time >= start_time) |> 
  #drop_na() |> 
  #filter(tiedot == "Naudanliha") |> 
  #mutate(time = lubridate::year(time)) |> 
  #group_by(tiedot, time) |> 
  #summarise(value = mean(value, na.rm=T)) |> 
  ptt_plot(
    title=  "Lihan tuottajahinnat",
    grouping = tiedot,
    subtitle = "%, muutos vuoden takaa",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |> 
  ptt_plot_add_prediction(pred_data = ennuste_data) |>
  ptt_plot_create_widget()
## \ Requesting get
## v Requesting get [138ms]
## 
## No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
## Using "lihan_tuottajahinnat" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/lihan_tuottajahinnat.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
# # Lihan kulutus ja tuotanto
# 
# liha_kulutus <-
#   ptt_data_robo("luke/02_Maatalous/08_Muut/02_Ravintotase/02_Ravintotase.px") |>
#   filter_recode(
#     tieto = c(
#       Tuotanto = "Tuotanto",
#       "Kokonaiskulutus" = "KOTIMAINEN KÄYTTÖ YHTEENSÄ"
#     ),
#     elintarvike = c(
#       "Naudanliha" = "Naudanliha 4)",
#       "Sianliha" = "Sianliha 4)",
#       "Siipikarjanliha" = "Siipikarjanliha 4)")
#   ) |>
#   rename(laji = elintarvike) |>
#   mutate(tiedot = paste(laji, "n ",  tolower(tieto), sep = ""),
#          time = time + months(6)) |>
#   filter(time >= start_time) 
#   
# ptt_data_robo_l("StatFin/vrm/kuol/statfin_kuol_pxt_12at.px")
# 
# 
# liha_kulutus|>
#   filter(laji == "Sianliha") |>
#    ptt_plot(
#     title=  "Sianlihan kulutus ja tuotanto Suomessa",
#     grouping = tiedot,
#     subtitle = "milj. kg",
#     caption =  "Lähde: Luke ja PTT",
#     rangeslider = FALSE,
#     zeroline = F,
#     hovertext =  list(rounding = 1, unit = "milj. kg", extra = "")
#   ) |> 
#   ptt_plot_add_prediction(pred_data = ennuste_data) |>
#   ptt_plot_create_widget()
# 
# 
# liha_kulutus|>
#   filter(laji == "Naudanliha") |>
#   ptt_plot(
#     title = "Naudanlihan kulutus ja tuotanto Suomessa",
#     subtitle = "milj. kg",
#     grouping = tiedot,
#     subtitle = "milj. kg",
#     caption =  "Lähde: Luke ja PTT",
#     rangeslider = FALSE,
#     zeroline = F,
#     hovertext =  list(rounding = 1, unit = "milj. kg", extra = "")
#   ) |> 
#   ptt_plot_add_prediction(pred_data = ennuste_data |> filter(luokka %in% )) |>
#   ptt_plot_create_widget()
# 
# liha_kulutus|>
#   filter(laji == "Siipikarjanliha") |>
#   filter(time >= start_time) |>
#   aplot_lines(colour = tieto, title = "Siipikarjanlihan kulutus ja tuotanto Suomessa",
#               subtitle = "milj. kg",
#               source = "Luke")

Tuotantopanokset

# Tuotantopanokset

ptt_data_robo_l("StatFin/hin/ttohi/statfin_ttohi_pxt_11gv.px") |>
  filter_recode(maatalouden_tuotantovalineiden_ostohintaindeksin_luokitus =
                  c("Energia" = "202000 ENERGIA, VOITELUAINEET",
                    "Lannoitteet" = "203000 LANNOITTEET JA MAANPARANNUSAINEET",
                    "Rehut" =  "206000 ELÄINTEN REHUT"), #,
                    #"Tuotantotarvikkeet yhteensä" = "200000 MAATALOUDEN TUOTANTOTARVIKKEET JA PALVELUT (Panos 1)"),
                tiedot = "Maatalouden tuotantovälineiden ostohintaindeksin vuosimuutos (2015=100)") |>
  filter(time >= start_time) |>
  mutate(tiedot = maatalouden_tuotantovalineiden_ostohintaindeksin_luokitus ) |> 
    ptt_plot(
    title = "Maatalouden tuotantopanosten hinnat",
    grouping = tiedot,
    subtitle = "%, vuosimuutos",
    caption =  "Lähde: Luke ja PTT",
    rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |> 
  ptt_plot_add_prediction(pred_data = ennuste_data) |>
  ptt_plot_create_widget()
## \ Requesting get
## v Requesting get [118ms]
## 
## Using "maatalouden_tuotantopanosten_hinnat" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/maatalouden_tuotantopanosten_hinnat.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>

Maataloudentilit

# Yrittäjätulo
taloustilit <- ptt_data_robo_l("StatFin/maa/eaa/statfin_eaa_pxt_12d7.px") |>
  filter(maatalouden_taloustili %in% c("18 Maataloustoimialan tuotos (16 + 17)",
                                       "31 Yrittäjätulo (27 - 28 - 29 + 30)",
                                       "19 Välituotekäyttö yhteensä",
                                       "21 Kiinteän pääoman kuluminen",
                                       "23 Palkansaajakorvaukset",
                                       "28 Maanvuokrat",
                                       "29 Korot, maksetut",
                                       "30 Korot, saadut",
                                       "25 Muut tuotantotukipalkkiot",
                                       "18 Maataloustoimialan tuotos (16 + 17)")  ) |>
  filter_recode(tiedot =c("th" = "Tuottajahintaan, käyvin hinnoin,  miljoonaa euroa",
                       "ph" = "Perushintaan, käyvin hinnoin, miljoonaa euroa")) |>
  separate(col = maatalouden_taloustili , into = c("id", "selite"), sep = " ", extra = "merge")|>

  mutate(tili_tiedot = paste(tiedot,id, sep = "_")) |>
  pivot_wider(id_cols = time, names_from = tili_tiedot, values_from =  value) |>
  mutate(maatal_yht = ph_18-th_18,
         kulut_yht = ph_19 + ph_21+ph_23 + ph_28 - ph_30 + ph_29,
         yrittajatulo = ph_31,
         maatalous_tuet = maatal_yht + ph_25,
         markkinatulot = th_18) |>
  filter(time >= start_time) |> 
  select(maatalous_tuet, kulut_yht, yrittajatulo, markkinatulot, time) |>
  pivot_longer(cols = maatalous_tuet:markkinatulot, names_to ="tiedot") |>
  mutate(tiedot = recode(tiedot, !!! c("yrittajatulo"= "Yrittäjätulo",
                                       "markkinatulot" = "Tulot markkinoilta",
                                       "maatalous_tuet" = "Maataloustuet yhteensä",
                                       "kulut_yht"= "Kulut yhteensä")))
## \ Requesting get
## v Requesting get [113ms]
## 
 ptt_plot(taloustilit,
  grouping = tiedot, 
  title ="Maatalouden taloustilit",
  subtitle = "milj. €",
    caption  = "Lähde: Tilastokeskus ja PTT",
   rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 0, unit = "milj. €", extra = "")
  ) |> 
  ptt_plot_add_prediction(pred_data = ennuste_data ) |>
  ptt_plot_create_widget()
## No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
## Using "maatalouden_taloustilit" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/maatalouden_taloustilit.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>

Elintarviketeollisuus

## Elintarviketeollisuus volyymi, liikevaihto

# volyymi

elintarvike_vol <- ptt_data_robo_l("StatFin/teo/ttvi/statfin_ttvi_pxt_111i.px") |>
  filter_recode(toimiala_tol_2008 =
                  c("Volyymi" = "10-11 Elintarviketeollisuus"  )) |>
  filter(tiedot == "Työpäiväkorjattu indeksisarja") |>
  mutate(tiedot = "Elintarviketeollisuus, tuotannon volyymi")
## \ Requesting get
## v Requesting get [191ms]
## 
elintarvike_lv <-ptt_data_robo_l("StatFin/teo/tlv/statfin_tlv_pxt_112c.px") |>
  filter_recode(toimiala =c("Liikevaihto" = "10-11 Elintarviketeollisuus"  )) |>
  filter(tiedot == "Työpäiväkorjattu indeksisarja",
         muuttuja == "Liikevaihto") |>
  mutate(tiedot = "Elintarviketeollisuus, liikevaihto")
## \ Requesting get
## v Requesting get [534ms]
## 
bind_rows(elintarvike_vol, elintarvike_lv) |>
  filter(time >= start_time) |>
  group_by(tiedot) |> 
  mutate(value = statfitools::trend_series(value, time = time, x11="")) |> 
  mutate(value= 100*(value / lag(value, n = 12, order_by = time)-1)) |>
  ungroup() |> 
  ptt_plot( grouping = tiedot, 
  title = "Elintarviketeollisuus",
  subtitle = "%, vuosimuutos",
    caption  = "Lähde: Tilastokeskus ja PTT",
       hovertext =  list(rounding = 1, unit = "%", extra = "") )|> 
  ptt_plot_add_prediction(pred_data = ennuste_data ) |>
  ptt_plot_create_widget()
## No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
## Using "elintarviketeollisuus" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarviketeollisuus.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
# Elintarvikkeiden tuonti ja vienti
dat_me_sitc <- ptt_data_robo(
  "tulli/uljas_sitc",
  dl_filter = list(
    "Tavaraluokitus SITC2" = c("00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
                               "11"),
    "Maa" = "AA",
    "Suunta" = c("Vienti määrämaittain", "Tuonti alkuperämaittain"),
    "Indikaattorit" = "Tilastoarvo (euro)"
  )
) |>
  filter_recode(
    suunta = c("Elintarvikkeiden vienti" = "Vienti määrämaittain",
               "Elintarvikkeiden tuonti" = "Tuonti alkuperämaittain")
  )
## \ Requesting get
## v Requesting get [61ms]
## 
dat_me_sitc |>
  filter(time >= start_time) |>
  group_by(maa, suunta, indikaattorit, time) |>
  summarise(value = 12 * sum(value)/1e6) |>
  mutate(tiedot = suunta,
         value = statfitools::trend_series(value, time = time, x11="")) |> 
  ungroup() |> 
  ptt_plot(
  grouping = tiedot, 
  title = "Elintarvikkeiden vienti ja tuonti",
  subtitle = "milj. euroa vuositasolle korotettuna",
    caption  = "Lähde: Tulli ja PTT",
   rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 0, unit = "milj. €", extra = "") )|> 
  ptt_plot_add_prediction(pred_data = ennuste_data ) |>
  ptt_plot_create_widget()
## `summarise()` has grouped output by 'maa', 'suunta', 'indikaattorit'. You can
## override using the `.groups` argument.
## No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
## Using "elintarvikkeiden_vienti_ja_tuonti" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarvikkeiden_vienti_ja_tuonti.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>

Ruuanhinta

# Elintarvikkeet
ptt_data_robo_l("StatFin/hin/khi/kk/statfin_khi_pxt_11xq.px") |> 
  filter(hyodyke %in% c("KULUTTAJAHINTAINDEKSI", "Elintarvikkeet", "ELINTARVIKKEET JA ALKOHOLITTOMAT JUOMAT")) |> 
  pivot_wider(names_from = indeksisarja, values_from =value, names_repair = "universal") |> 
  group_by(hyodyke) |> 
  mutate(across(where(is.numeric), ~100* (.x / lag(.x, n = 12, order_by = time) - 1))) |> 
  ungroup() |> 
  filter(time >= start_time) |> 
  mutate(value = coalesce(KHI.2015.100, KHI.2010.100, KHI.2005.100, KHI.2000.100)) |> 
  select(!c(KHI.2015.100, KHI.2010.100, KHI.2005.100, KHI.2000.100)) |> 
  mutate(tiedot = str_to_sentence(hyodyke)) |> 
  mutate(tiedot = fct_recode(tiedot, Kuluttajahinnat = "Kuluttajahintaindeksi")) |>
  ptt_plot(
  grouping = tiedot, 
  title = "Elintarvikkeiden hinnat",
  subtitle =  "%, muutos vuoden takaa",
    caption  = "", #Lähde: Tilastokeskus ja PTT",
   rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "%", extra = "") )|> 
  ptt_plot_add_prediction(pred_data = ennuste_data ) |>
  ptt_plot_create_widget()
## \ Requesting get
## v Requesting get [99ms]
## 
## New names:
## * `KHI 2015=100` -> KHI.2015.100
## * `KHI 2010=100` -> KHI.2010.100
## * `KHI 2005=100` -> KHI.2005.100
## * `KHI 2000=100` -> KHI.2000.100
## No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
## Using "elintarvikkeiden_hinnat" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarvikkeiden_hinnat.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
ptt_data_robo_l("StatFin/hin/khi/kk/statfin_khi_pxt_11xq.px") |> 
  filter(hyodyke %in% c("KULUTTAJAHINTAINDEKSI", "Elintarvikkeet", "ELINTARVIKKEET JA ALKOHOLITTOMAT JUOMAT")) |> 
  pivot_wider(names_from = indeksisarja, values_from =value, names_repair = "universal") |> 
  group_by(hyodyke) |> 
  mutate(across(where(is.numeric), ~100* (.x / lag(.x, n = 12, order_by = time) - 1))) |> 
  ungroup() |> 
  #filter(time >= start_time) |> 
  mutate(value = coalesce(KHI.2015.100, KHI.2010.100, KHI.2005.100, KHI.2000.100)) |> 
  select(!c(KHI.2015.100, KHI.2010.100, KHI.2005.100, KHI.2000.100)) |> 
  mutate(tiedot = str_to_sentence(hyodyke)) |> 
  mutate(tiedot = fct_recode(tiedot, Kuluttajahinnat = "Kuluttajahintaindeksi")) |>
  mutate(year = lubridate::year(time)) |> 
  group_by(year, hyodyke) |> 
  summarise(value = mean(value, na.rm=T)) |> filter(hyodyke == "Elintarvikkeet") |>  view()
## \ Requesting get
## i Object retrieved from client cache (valid until 2022-03-29 08:30:08).
## \ Requesting get
v Requesting get [51ms]
## 
## New names:
## * `KHI 2015=100` -> KHI.2015.100
## * `KHI 2010=100` -> KHI.2010.100
## * `KHI 2005=100` -> KHI.2005.100
## * `KHI 2000=100` -> KHI.2000.100
## `summarise()` has grouped output by 'year'. You can override using the `.groups` argument.
# Elintarvikeryhmien hinnan muutos

ptt_data_robo_l("StatFin/hin/khi/kk/statfin_khi_pxt_11xd.px") |> 
  filter_recode(hyodyke = 
    c(
    "Viljatuotteet ja leipä" = "01.1.1 Viljatuotteet ja leipä",
    "Liha" = "01.1.2 Liha",
    "Maitotuotteet, juusto ja kananmunat" = "01.1.4 Maitotuotteet, juusto ja kananmunat"
    ),
         tiedot = c("Vuosimuutos (%)")
  ) |> 
  mutate(tiedot = hyodyke) |> 
  filter(time >= start_time) |> 
  ptt_plot(
  grouping = tiedot, 
  title = "Elintarvikkeryhmien hinnat",
    subtitle = "%, muutos vuoden takaa",
    caption  = "", # Lähde: Tilastokeskus ja PTT",
   rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "%", extra = "") )|> 
  ptt_plot_add_prediction(pred_data = ennuste_data |> 
                            filter(luokka == "Elintarvikkeiden hintojen muutos")) |>
  ptt_plot_create_widget()
## \ Requesting get
## v Requesting get [602ms]
## 
## Using "elintarvikkeryhmien_hinnat" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarvikkeryhmien_hinnat.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>

Yrittäjätulo

ennuste_data |>
  filter(luokka %in% c("Tulot markkinoilta","Kulut yhteensä","Maataloustuet yhteensä","Yrittäjätulo")) |>
  pivot_longer(cols = `2014`:`2023`, names_to = "time", values_to = "value") |>
  filter(time < 2022) |>
  mutate(tiedot = sarja_nmi,
         time = ymd(paste(time, "-1-1", sep = ""))) |>
  ptt_plot(
    grouping = tiedot,
    title ="Maatalouden yrittäjätulo",
    subtitle = "milj. euroa",
    caption  = "Lähde: Eurostat ja PTT",
    rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit ="milj. euroa", extra = "")) |>
  ptt_plot_add_prediction(pred_data = ennuste_data |>
                            filter(luokka %in% c("Tulot markkinoilta","Kulut yhteensä","Maataloustuet yhteensä","Yrittäjätulo"))) |>
  ptt_plot_create_widget()
## No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
## Using "maatalouden_yrittajatulo" for htmlwidget filename..
## 
## <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ptt_me_ennustekuvat_artefacts/maatalouden_yrittajatulo.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>

Upload

ptt_plot_upload_widgets()
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarviketeollisuus.html
## i 2022-03-29 08:30:02 > File size detected as  59.2 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarvikkeet_ja_alkoholittomat_juomat.html
## i 2022-03-29 08:30:02 > File size detected as  73.2 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarvikkeiden_hinnat.html
## i 2022-03-29 08:30:03 > File size detected as  76 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarvikkeiden_vienti_ja_tuonti.html
## i 2022-03-29 08:30:03 > File size detected as  59.2 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/elintarvikkeryhmien_hinnat.html
## i 2022-03-29 08:30:03 > File size detected as  69.9 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/lihan_tuottajahinnat.html
## i 2022-03-29 08:30:04 > File size detected as  70.1 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/maailman_viljantuotanto.html
## i 2022-03-29 08:30:04 > File size detected as  22.4 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/maatalouden_taloustilit.html
## i 2022-03-29 08:30:04 > File size detected as  37.4 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/maatalouden_tuotantopanosten_hinnat.html
## i 2022-03-29 08:30:04 > File size detected as  52.6 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/maatalouden_yrittajatulo.html
## i 2022-03-29 08:30:04 > File size detected as  37.1 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/maidon_tuotanto_suomessa.html
## i 2022-03-29 08:30:05 > File size detected as  22.6 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/maidon_tuottajahinta.html
## i 2022-03-29 08:30:05 > File size detected as  70.7 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/crosstalk-1.2.0/css/crosstalk.min.css
## i 2022-03-29 08:30:05 > File size detected as  1.3 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/crosstalk-1.2.0/js/crosstalk.js
## i 2022-03-29 08:30:05 > File size detected as  47.9 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/crosstalk-1.2.0/js/crosstalk.js.map
## i 2022-03-29 08:30:05 > File size detected as  53.6 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/crosstalk-1.2.0/js/crosstalk.min.js
## i 2022-03-29 08:30:06 > File size detected as  18.5 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/crosstalk-1.2.0/js/crosstalk.min.js.map
## i 2022-03-29 08:30:06 > File size detected as  49.2 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/crosstalk-1.2.0/scss/crosstalk.scss
## i 2022-03-29 08:30:06 > File size detected as  1.8 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/htmlwidgets-1.5.4/htmlwidgets.js
## i 2022-03-29 08:30:06 > File size detected as  32.4 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/jquery-3.5.1/jquery-AUTHORS.txt
## i 2022-03-29 08:30:06 > File size detected as  13.1 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/jquery-3.5.1/jquery.js
## i 2022-03-29 08:30:07 > File size detected as  280.9 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/jquery-3.5.1/jquery.min.js
## i 2022-03-29 08:30:07 > File size detected as  87.4 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/jquery-3.5.1/jquery.min.map
## i 2022-03-29 08:30:07 > File size detected as  134.8 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/plotly-binding-4.10.0/plotly.js
## i 2022-03-29 08:30:08 > File size detected as  32.9 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/plotly-htmlwidgets-css-2.5.1/plotly-htmlwidgets.css
## i 2022-03-29 08:30:08 > File size detected as  173 bytes
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/plotly-locale-fi-2.5.1/fi.js
## i 2022-03-29 08:30:08 > File size detected as  3.1 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/plotly-main-2.5.1/plotly-latest.min.js
## i 2022-03-29 08:30:08 > File size detected as  3.4 Mb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/plot_dependencies/typedarray-0.1/typedarray.min.js
## i 2022-03-29 08:30:09 > File size detected as  21.9 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/sianlihan_kulutus_ja_tuotanto_suomessa.html
## i 2022-03-29 08:30:09 > File size detected as  26.6 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/viljan_hintanoteeraukset_suomessa.html
## i 2022-03-29 08:30:09 > File size detected as  201 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/viljan_tuotanto_suomessa.html
## i 2022-03-29 08:30:09 > File size detected as  34.5 Kb
## Uploading ennustekuvat/ptt_me_ennustekuvat_artefacts/viljan_tuottajahinnat_suomessa.html
## i 2022-03-29 08:30:10 > File size detected as  61.8 Kb